if(window.widget)
{
	widget.setNavigationEnabled(false);
	menu.hideSoftkeys();
}

function init()
{
	// Initializing the main GBC object, that will initialize and manage the widget
	window.GBC = new Nokia.GBC();

	// Removing the splash screen IMG node
	var splash = document.getElementById('splash_image');
	splash.parentNode.removeChild(splash);

	// Rendering the first GBC view
	GBC.render();
};

/*
 * Handles the dynamic load of the widget's CSS and JS resources
 */
function loadWidgetResources()
{
	// Dynamically loading JavaScript libraries
	initJsFile('lib/guarana/lib/jquery/jquery.js');
	initJsFile('lib/guarana/lib/Guarana.js');
	initJsFile('impl/core-defaults.js');

	var width = window.innerWidth;
	var height = window.innerHeight;

	var deviceResolution = width + 'x' + height;
	var themeName = 'default';

	// Dynamically loading CSS stylesheets
    initCssFile('lib/guarana/themes/themeroller/' + themeName + '-theme/Themeroller.css');
	initCssFile('lib/guarana/themes/nokia/ext-theme/' + themeName + '/' + deviceResolution + '/custom.css');
	initCssFile('css/reset.css');
	initCssFile('css/basic.css');
	initCssFile('css/guarana-custom.css');
	
	window.addEventListener('load', widgetResourcesLoaded, false);
};

/*
 * Dynamically load a single JavaScript source file
 */
function initJsFile(src) {
	document.write("<script type=\"text/javascript\" src=\"" + src + "\"></script>");
};

/*
 * Dynamically load a single CSS stylesheet
 */
function initCssFile(src) {
	var style = document.createElement('link');
	style.setAttribute('rel', "stylesheet");
	style.setAttribute('type', "text/css")
	style.setAttribute('href', src);
	document.getElementsByTagName('head')[0].appendChild(style);
};

/*
 * Method called when the widget's CSS and JS resources are loaded
 */
function widgetResourcesLoaded()
{
	// Loading the Guarana and widget-specific resources needed by GBC
	// (dependencies are defined in the 'impl/core-defaults.js' file)
	Nokia.use('gbc', init);
}

loadWidgetResources();